// 查询所有的资源菜单列表
function loadResourceMenu() {
    $.ajax({
        type: "GET",
        url: "/resource/list",
        dataType: "json",
        data: {
            pageNum: 1,
            pageSize: 100
        },
        success: function (res) {
            if (res.code === 200) {
                let list = res.pageInfo.list;
                // alert(list)
                let tdArea = $("#resourceMenu");
                let str = "";
                list.map(obj => {
                    str +=
                        `<ul><label class='checkbox inline'><input type='checkbox' name='group[]' value='${obj.mId}'/> ${obj.mName}</label></ul>`;
                })
                // alert(str)
                tdArea.html(str);
            } else {
                alert("服务器开小差了")
            }
        }
    })
}


function roleSave() {
    // 禁用表单登录
    event.preventDefault();

    let rId = $('input[name="rId"]').val();
    // alert("rId = " + rId);
    let rName = $('input[name="rName"]').val();
    let rState = $('input[name="rState"]').val();
    // alert(rName);
    // alert(rState)
    let menuList = $(':checkbox[name="group[]"]:checked');
    let mIdList = []
    let mIds = "";
    menuList.each(function () {
        mIdList.push($(this).val());
    });
    mIds = mIdList.join(",");
    // alert(mIds)

    $.ajax({
        type: "POST",
        url: "/role/save",
        dataType: "json",
        data: {
            rId,
            rName,
            rState,
            mIds
        },
        success: function (res) {
            if (res.code === 200) {
                alert("操作成功");
                window.location.href = "index.html";
            } else {
                alert("操作失败")
            }
        }
    })
}